package com.example.test.启动线程.线程池;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main1 {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(1);

//        ThreadLocal<String> threadLocal = ThreadLocal.withInitial(String::new);
        InheritableThreadLocal<String> threadLocal = new InheritableThreadLocal<>();

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                String name = Thread.currentThread().getName();
                System.out.println(name);
                threadLocal.set(name);

                Runnable runnable1 = new Runnable() {
                    @Override
                    public void run() {
                        System.out.println("获取到的名字" + threadLocal.get());
                    }
                };

                executorService.execute(runnable1);
            }
        };


        new Thread(runnable).start();
        new Thread(runnable).start();

    }
}
